package com.gem.service.impl;

import com.gem.entity.Commodity;
import com.gem.mapper.CommodityMapper;
import com.gem.service.CommodityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
 * @author zhang
 * @date 2020/10/4 15:38
 */
@Service
public class CommodityServiceImpl implements CommodityService {

    @Autowired
    CommodityMapper commodityMapper;

    @Override
    public PageInfo<Commodity> findCommoditysByPagesAndName(int pageNow, int pageSize, String name) {

        //设置分页参数
        PageHelper.startPage(pageNow,pageSize,true);
        List<Commodity> commodities = commodityMapper.selectByName(name);
        PageInfo<Commodity> pageInfo = new PageInfo<>(commodities);
        return pageInfo;
    }

    @Override
    public PageInfo<Commodity> findCommoditysByPagesAndType(int pageNow, int pageSize, String type) {
        //设置分页参数
        PageHelper.startPage(pageNow,pageSize,true);
        List<Commodity> commodities = commodityMapper.selectByType(type);
        PageInfo<Commodity> pageInfo = new PageInfo<>(commodities);
        return pageInfo;
    }

    @Override
    public List<String> findAllType() {
        return commodityMapper.selectAllType();
    }

    @Override
    public Commodity findCommodityById(int id) {
        return commodityMapper.selectCommodityById(id);
    }

    @Override
    public List<Commodity> findCommoditiesByNameAndType(String name, String type) {
        return commodityMapper.selectCommodityByNameAndType(name, type);
    }

    @Override
    public List<Commodity> findAllCommodities() {
        return commodityMapper.selectAllCommoditys();
    }

    @Override
    public PageInfo<Commodity> findCommoditysByName(int pageNow, int pageSize, String name) {
        //设置分页参数
        PageHelper.startPage(pageNow,pageSize,true);
        List<Commodity> commodities = commodityMapper.selectByName(name);
        PageInfo<Commodity> pageInfo = new PageInfo<>(commodities);
        return pageInfo;
    }

    @Override
    public List<Map<String, String>> findNumByType() {
        return commodityMapper.selectNumByType();
    }
}
